let session = require("express-session");
const express = require("express");
let app = express();

app.use(
  session({
    name: "myid",
    secret: "mysecret",
    resave: true,
    saveUninitialized: true,
    cookie: {
      maxAge: 3600 * 1000,
      httpOnly: true,
    },
  })
);

app.get("/setsession", (req, res) => {
  req.session.username = "zs";
  res.send("设置session");
});

app.get("/getsession", (req, res) => {
  // 获取session的值
  console.log(req.session.username);
  res.send("hello" + req.session.username);
});

app.get("/delsession", (req, res) => {
  // 删除session
  req.session.destroy();
  res.send("删除session");
});

app.listen(8080);
